import { UserRegisterDto } from './dto/user-register.dto';
import { UserInfoDto } from './dto/user-info.dto';
import { Injectable } from '@nestjs/common';
import { UserLoginDto } from './dto/user-login.dto';
import { InjectRepository } from '@nestjs/typeorm';
import { UserBase } from './entities/user.entity';
import { Repository } from 'typeorm';
// import { InjectRepository } from '@nestjs/typeorm';
// import { Repository } from 'typeorm';

@Injectable()
export class UserService {

  constructor(
    @InjectRepository(UserBase)
    private usersRepository: Repository<UserBase>
  ) { }

  findAll(): Promise<UserBase[]> {
    return this.usersRepository.find();
  }

  userLogin(userLoginDto: UserLoginDto): UserInfoDto {
    return { ...userLoginDto, userId: `${new Date().getTime()}` };
  }

  userRegister(userRegisterDto: UserRegisterDto) {
    const userBase = new UserBase();
    const { name, password, email, gender, mobile } = userRegisterDto;
    userBase.name = name
    userBase.password = password
    userBase.email = email
    userBase.gender = gender
    userBase.mobile = mobile
    return this.usersRepository.insert(userBase)
  }

  userInfo(): Promise<UserInfoDto> {
    return new Promise((resolve) => {
      resolve({
        name: 'zhangsan',
        password: '123',
        userId: `${new Date().getTime()}`,
      })
    });
  }

  userSearch(keyword: string) {
    console.log('keyword :>> ', keyword);
    return {
      keyword: keyword,
      name: 'zhangsan',
      password: '123',
      userId: `${new Date().getTime()}`,
    };
  }
}
